<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <script type="text/javascript" src="/static/h-ui/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/h-ui/lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="/static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="/static/h-ui/js/H-ui.admin.page.js"></script>
</head>

<body>
    <div class="cl pd-5 bg-1 bk-gray">
        <a href="{:url('/file_manager/selectpicture')}" class="btn btn-default radius sethumb">
            <i class="Hui-iconfont">&#xe600;</i> 站内选择 </a>&nbsp;&nbsp;
        <a href="{:url('/file_manager/uploadpicture')}" class="btn btn-default radius sethumb">
            <i class="Hui-iconfont">&#xe600;</i> 本地上传 </a>&nbsp;&nbsp;
        <a href="javascript:void(0);" class="btn btn-primary radius sethumb">
            <i class="Hui-iconfont">&#xe600;</i> 网络图片 </a>&nbsp;&nbsp;
    </div>
    <!-- 网络图片-->
    <div class="step2 active" style="margin-top:40px;margin-left:30px;">
        <div class="row cl" >
            <label class="form-label col-xs-2 col-sm-2">
                <span class="c-red">*</span>图片地址：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" name="onlineImg" id="onlineImg" value="" placeholder="将图片地址黏贴至此">
            </div>
            <div class="col-3"> </div>
        </div>
        <div class="row cl" style="margin-top:20px;">
            <label class="form-label col-xs-2 col-sm-2">下载图片：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <div class="radio-box">
                    <input name="download" type="radio" id="download-1" value="0" checked>
                    <label for="sex-1">否</label>
                </div>
                <div class="radio-box">
                    <input name="download" type="radio" id="download-2" value="1">
                    <label for="sex-2">是</label>
                </div>
            </div>
        </div>
        <div class="row cl" style="margin-top:20px;">
            <label class="form-label col-xs-2 col-sm-2">生成缩略图：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <div class="radio-box">
                    <input name="isthumb" type="radio" id="isthumb-1" value="0" checked>
                    <label for="sex-1">否</label>
                </div>
                <div class="radio-box">
                    <input name="isthumb" type="radio" id="isthumb-2" value="1">
                    <label for="sex-2">是</label>
                </div>
            </div>
        </div>
        <div class="row cl" style="margin-top:20px;">
            <label class="form-label col-xs-2 col-sm-2">保留原文件名：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <div class="radio-box">
                    <input name="formername" type="radio" id="name-1" value="0" checked>
                    <label for="sex-2">否</label>
                </div>
                <div class="radio-box">
                    <input name="formername" type="radio" id="name-2" value="1">
                    <label for="sex-1">是</label>
                </div>
            </div>
        </div>
        <div class="row cl" style="margin-top:30px;margin-left:30px;">
            <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
                <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;" onCLick="oSelectImg()">
                <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
                    onClick="layer_close();">
            </div>
        </div>
    </div>
    <!-- 网络图片end-->

    <!-- <script type="text/javascript" src="/static/js/jquery.form.js"></script> -->
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">
        function oSelectImg() {
            var onlineImg = $("#onlineImg").val();
            if (onlineImg == '') {
                layer.msg('图片地址为空', {
                    icon: 5,
                    time: 1000
                });
                return false;
            } else {
                var download = $('input:radio[name="download"]:checked').val();
                if (download==1) {
                    var isthumb = $('input:radio[name="isthumb"]:checked').val();
                    var formername = $('input:radio[name="formername"]:checked').val();
                    $.ajax({
                        url: '{:url("/file_manager/onlinePicture")}',
                        type: 'POST',
                        data: {
                            'filename': onlineImg,
                            'isthumb': isthumb,
                            'formername': formername,
                            'download': download,
                        },
                        dataType: "json",
                        success:function(data) {
                            // console.log(data);
                            if (data.code == 2) {
                                var imgname = '';
                                if (isthumb==1) {
                                    imgname = '/upload/' + data.thumbname;
                                } else {
                                    imgname = '/upload/' + data.filename;
                                }

                                window.parent.$("#showthumb").attr('src', imgname);
                                window.parent.$("#thumb").val(imgname);
                                layer_close();
                            } else {
                                layer.msg(data.msg, {
                                    icon: 5,
                                    time: 1000
                                });
                                return false;
                            }
                        },
                        error:function(XMLHttpRequest) {
                            layer.msg('请求出错请稍后再试', {
                                    icon: 5,
                                    time: 1000
                                });
                            return false;
                        }
                    });
                } else {
                    $.ajax({
                        url: '{:url("/file_manager/isimg")}',
                        type: 'POST',
                        data: {'filename': onlineImg},
                        dataType: "json",
                        success:function(data) {
                             // console.log(data);
                            if (data.code == 2) {
                                window.parent.$("#showthumb").attr('src', onlineImg);
                                window.parent.$("#thumb").val(onlineImg);
                                layer_close();
                            } else {
                                layer.msg(data.msg, {
                                    icon: 5,
                                    time: 1000
                                });
                                return false;
                            }
                        },
                        error:function(XMLHttpRequest) {
                            layer.msg('请求出错请稍后再试', {
                                    icon: 5,
                                    time: 1000
                                });
                                return false;
                        }
                    });
                }

            }
        }
    </script>
    <!--请在上方写此页面业务相关的脚本-->
</body>

</html>